package com.lzw.strategy.demo1;

import com.lzw.strategy.demo1.pojo.People;
import com.lzw.strategy.demo1.sub.AmericaAbstractPeopleStrategy;
import com.lzw.strategy.demo1.sub.ChineseAbstractPeopleStrategy;
import com.lzw.strategy.demo1.util.Constant;
import com.lzw.strategy.demo1.util.SpringUtil;

/**
 * @author Chengfei
 * @Description
 * @date 2024/5/14
 */
public class PeopleStrategyFactory {

    public PeopleStrategy getStrategy(People people) {
        String nationality = people.getNationality();

        // 中国
        if (Constant.NATIONALITY_CHINA.equals(nationality)) {
            return SpringUtil.getBean(ChineseAbstractPeopleStrategy.class);
        }
        // 美国
        if (Constant.NATIONALITY_USA.equals(nationality)) {
            return SpringUtil.getBean(AmericaAbstractPeopleStrategy.class);
        }

        throw new NullPointerException("未找到对应处理器");

    }
}
